package com.lsq.baseadmin.modules.maintenance.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lsq.baseadmin.modules.maintenance.entity.ScheduleJobLog;
import com.lsq.baseadmin.modules.maintenance.mapper.ScheduleJobLogMapper;
import com.lsq.baseadmin.modules.maintenance.service.ScheduleJobLogService;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lsq
 * @since 2020-11-11
 */
@Service
public class ScheduleJobLogServiceImpl extends ServiceImpl<ScheduleJobLogMapper, ScheduleJobLog> implements ScheduleJobLogService {

    @Override
    public List<ScheduleJobLog> list(ScheduleJobLog entity) {
        QueryWrapper<ScheduleJobLog> wrapper = createWrapper(entity);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public PageInfo pg(ScheduleJobLog entity, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ScheduleJobLog> list = list(entity);
        return new PageInfo<>(list);
    }

    private QueryWrapper<ScheduleJobLog> createWrapper(ScheduleJobLog entity) {
        QueryWrapper<ScheduleJobLog> wrapper = new QueryWrapper<>();
        if (null == entity) {
            return wrapper;
        }

        if (entity.getJobId() != null) {
            wrapper.like("job_id", entity.getJobId());
        }
        if (StringUtils.hasText(entity.getJobName())) {
            wrapper.like("job_name", entity.getJobName());
        }
        if (entity.getStatus() != null) {
            wrapper.like("status", entity.getStatus());
        }

        return wrapper;
    }
}
